﻿<script type="text/javascript">
    $(document).ready(function () {
        $('.fAccepted').click(function () {
            var link = $(this);
            $.getJSON("/CoreService.svc/AcceptFriendRequest?r=" + $(this).attr('data-id'), function (result) {
                if (result.d.AcceptFriendRequest) {
                    link.parent().parent().hide();
                }
            });
        });
        $('.fDenied').click(function () {
            var link = $(this);
            $.getJSON("/CoreService.svc/RejectFriendRequest?r=" + $(this).attr('data-id'), function (result) {
                if (result.d.RejectFriendRequest) {
                    link.parent().parent().hide();
                }
            });
        });
    });
</script>
<h2>@ViewBag.Title</h2>
<div id="FRequests">
    <h3><a href="#">@ViewBag.RequestFor</a></h3>
    <div>
        <table border="1">
            @if (ViewBag.ForYou != null)
            {
                foreach (var r in ViewBag.ForYou)
                {
            <tr>
                <td><a href="/@r.Profiles.UserName /Home"><img height="40" src="@r.Profiles.Avatar" alt="avatar" /></a></td>
                <td><a href="/@r.Profiles.UserName /Home">@r.Profiles.DisplayName</a></td>
                <td>@r.FRTime</td>
                <td>@r.FRHi</td>
                <td><a data-id="@r.FRId" class="fAccepted">Accept</a>/<a data-id="@r.FRId" class="fDenied">Refuse</a></td>
            </tr>
                }
            }
        </table>
    </div>
    <h3><a href="#">@ViewBag.RequestBy</a></h3>
    <div>
        <table border="1">
            @if (ViewBag.ByYou != null)
            {
                foreach (var r in ViewBag.ByYou)
                {
            <tr>
                <td><a href="/@r.Friend.UserName/Home"><img height="40" src="@r.Friend.Avatar" alt="avatar" /></a></td>
                <td><a href="/@r.Friend.UserName/Home">@r.Friend.DisplayName</a></td>
                <td>@r.FRTime</td>
                <td>@r.FRHi</td>
                <td><a class="fDenied">Remove</a></td>
            </tr>
                }
            }
        </table>
    </div>
</div>
